<template>
	<view class="WebView">
		<view v-if="hasCustomer" class="hasCustomer">
			<!-- <web-view src="https://www.baidu.com"></web-view> -->
			<web-view :webview-styles="webviewStyles" :src="SRC"></web-view>
		</view>

		<view v-else class="hasCustomer">

			<!-- loading -->
			<!-- {{windowHeight}} -->
			<view v-if="!AddCustomer" :style="{'margin-top': (windowHeight/2 - 150) + 'px'}" class="loading">
				<u-loading style=" margin-left: 300rpx;" mode="flower" size="150"></u-loading>
			</view>
			<!-- 添加套账 -->
			<view v-else class="AddCustomer" :style="{'padding-top': (windowHeight/2 - 150) + 'px','text-align': 'center'}">
				<view style="text-align: center;font-size: 50upx;color: #ff5500;font-weight: 600;margin-bottom: 20upx;">
					当前没绑定账套,请添加账套 
				</view>
				<u-button type="success" size="medium" @click="AddCustomerFun">添加账套</u-button>
				<view style="height: 50upx;"></view>
				<u-button type="success" size="medium" @click="resfsh">刷新</u-button>
			</view>
		</view>
	</view>
</template>
<script>
	import http from '../../common/vmeitime-http/index.js';
	import {
		Base64Encrypt,
		Base64Decrypt,
		Decrypt,
		EncryptAES,
		SHA256,
		RSA_encrypt,
		RSA
	} from '../../utils/crypto_RSA_AES.js'
	export default {
		data() {
			return {
				Custome: null,
				SRC: '',
				windowHeight: null,
				hasCustomer: false,
				AddCustomer: false,
				 webviewStyles: {
					progress: {
						color: '#FF3333'
					}
				}
			}
		},
		created() {
			
		},
		onShow() {
			this.getData();
		},
		//
		onReady() {
			const {
				windowWidth,
				windowHeight
			} = uni.getSystemInfoSync();
			this.windowHeight = windowHeight;
		},
		// 
		methods: {
			resfsh() {
				this.hasCustomer = false
				this.AddCustomer = false
				this.getData()
			},
			getData() {
				let that = this;
				http.GetCustomerList().then(res => {
					that.AddCustomer = true;
					if (res.data.customerlist.length) {
						that.hasCustomer = true;
						that.Custome = res.data.customerlist[0];
						let options =res.data.customerlist[0];
						let CustomerName = options.CName;
						let UserPassWord = Base64Decrypt(options.PPassword, uni.getStorageSync('AKey'), uni.getStorageSync('AIV'));

						let UserName, authMode;
						let arr = ['MobilePhone', 'CardData', 'IdentityCard'];
						for (let i = 0; i < arr.length; i++) {
							if (options[arr[i]]) {
								UserName = options[arr[i]];
								authMode = arr.length - i;
								break;
							}
						}
						console.log(
							`https://yun.pc15.net/WebUI/phone/PersonWap/index.html#/Index?CustomerName=${CustomerName}&UserName=${UserName}&UserPassWord=${UserPassWord}&authMode=${authMode}`
							// `https://192.168.1.168:8080/#/Index?CustomerName=${CustomerName}&UserName=${UserName}&UserPassWord=${UserPassWord}&authMode=${authMode}`
						)
						// console.log(document.querySelectorAll("webview"))
						// document.querySelectorAll("webview")[1].showDevTools(true);
						this.SRC = `https://yun.pc15.net/WebUI/phone/PersonWap/index.html#/Index?CustomerName=${CustomerName}&UserName=${UserName}&UserPassWord=${UserPassWord}&authMode=${authMode}`
						// that.SRC = `https://192.168.1.168:8080/#/Index?CustomerName=${CustomerName}&UserName=${UserName}&UserPassWord=${UserPassWord}&authMode=${authMode}`




					} else {
						that.hasCustomer = false;
					}
				}).catch(err => {
					that.AddCustomer = false;
				})
			},
			//
			AddCustomerFun(){
				uni.navigateTo({
				    url: '../AddPerson/AddPerson'
				});
			}
		}
	}
</script>
<style lang="scss">
	.WebView {

		width: 100%;
		height: 100%;
		overflow-y: auto;

		.hasCustomer {
			height: 100%;
			overflow-y: auto;
			padding-bottom: 120rpx;
		}




	}
</style>
